import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteMockServe } from 'vite-plugin-mock'
// https://vitejs.dev/config/
export default defineConfig({
  // base: '/hm', // 在此处配置路由基地址
  plugins: [
    viteMockServe({
      // default
      mockPath: './src/mock',
      enable: true
    }),
    createHtmlPlugin(),
    vue(),
    Components({
      dts: false, // 禁止生成组件的d.ts文件
      // 组件自动注册会自动引入组件和自动引入样式 importStyle: false 阻止再次引入样式
      resolvers: [VantResolver({ importStyle: false })]
    }),
    createSvgIconsPlugin({
      // eslint-disable-next-line no-undef
      iconDirs: [path.resolve(process.cwd(), 'src/icons')]
    }),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'], // 自动导入vue和vue-router相关函数
      dts: 'src/auto-import.d.ts' // 生成 `auto-import.d.ts` 全局声明
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 80
  }
})
